* Generate regression results, tables and marginsplot graphs

clear

mkdir ~/Desktop/Results/

cd ~/Desktop/

use qatar_attitude_weighted_pub

**************************************
*Coding Key Independent Variables
**************************************

gen region5 = region
replace region5 = 5 if region5>5 & region5!=.


label define region5 0 "Qatar" 1 "Arab" 2 "West" 3 "South Asia" 4 "East Asia" 5 "Other",replace

label value region5 region5


*Survey participation
gen survey_ask = surveypart
replace survey_ask=0 if surveypart==2
replace survey_ask=0 if surveypart==-8

sum survey_ask

gen how_many = howmany
replace how_many = 1 if how_many ==-8

gen ask_count = survey_ask
replace ask_c = how_many if survey_ask==1

 
gen survalue_1 = survalue1
gen survalue_2 = survalue2
gen survalue_3 = survalue3

gen burden_1 = burden1
gen burden_2 = burden2
 
foreach x of varlist survalue_* burden_* {
replace `x' =. if `x'<1
}


*Demographics
*gender year educ1 class

gen formal_edu=educ1
replace formal=. if formal<0
replace formal=0 if formal==2

gen edu_12year= educ2
replace edu_12 = 0 if formal==0
replace edu_12 = 0 if educ2==2

gen yearborn=year
replace yearborn=. if yearborn>3000
replace yearborn=. if yearborn<1900


gen social_class=1 if class == 5
replace social_class = 2 if class == 4
replace social_class = 3 if class == 3
replace social_class = 4 if class == 2
replace social_class = 5 if class == 1
replace social_c=. if class<0

label var social_class "Socioeconomic status/class"

**************************************
*Coding Dependent Variable
**************************************

*Birthday question
gen misreport = skipexp
replace misreport = 0 if misreport==1 
replace misreport = 1 if misreport==2
replace misreport = . if misreport<0

**************************************
*Coding Independent Variables
**************************************

*Education
gen ed3 = formal_ed
replace ed3=2 if edu_12year==1

gen ed4 = ed3
replace ed4 = 3 if educ4>3 & educ4<7

gen region3 = region5
replace region3=2 if region3>2 & region3<88
replace region3=3 if region3==2
replace region3=2 if region3==1
replace region3=1 if region3==0
label def region3 1 "Qatar" 2 "Arab" 3 "Non-Arab"
label val region3 region3
tab region3

gen male=0 if gender == 2
replace male = 1 if gender == 1

*cleaning year
replace year = 1965 if year == 19651
replace year = 1969 if year == 19698
replace year = 1978 if year == 19781
replace year = 1989 if year == 19890
replace year = 1996 if year == 19961
replace year = 1987 if year == 191987
replace year = 1984 if year == 1884
replace year = 1980 if year == 1880
replace year = 1980 if year == 1080

gen temp=year if year<1000
replace temp = 97 if temp == 979
replace temp = 97 if temp == 977
replace temp = 19 if temp == 199
replace temp = age if temp<0
replace temp = . if temp==0
replace temp = . if temp == 1

*generate age
rename age agebin
gen age = 2017 - year if year>1000
replace age = temp if age==.
replace age = . if age < 10

drop temp


* class
gen lowerclass=0 if class>0
replace lowerclass = 1 if class == 4 | class == 5

gen midupper = 1 if lowerclass == 0 & class >0
replace midupper = 0 if lowerclass == 1

label var midupper "Upper/Middle Class"

label def midupper 0 "Lower Class" 1 "Upper/Middle Class"
label val midupper midupper 

gen upper = 0 if class>0
replace upper =1 if class == 1

label var upper "Upper-Class"

gen middle = 0 if class>0
replace middle = 1 if class == 2 | class == 3

label var middle "Middle Class"

label def middle 0 "Middle Class" 1 "Lower Class" , modify
label val lowerclass lowerclass

* disinterested
gen disinterested = x1


foreach var of varlist truthful influenced mislead  {
gen `var'_4=1 if `var'==4
replace `var'_4=2 if `var'==3
replace `var'_4=3 if `var'==2
replace `var'_4=4 if `var'==1
}


gen bachelors = 0 if educ1~=.
replace bachelors = 1 if educ4>3& educ4<7
tab bachelors educ4
tab educ4 bachelors

*Arab sample: education and integrity
gen noformal=1 if formal==0
replace noformal=0 if formal==1
label def noformal 0 "Some Formal Ed" 1 "No Formal Ed"
label val noformal noformal


gen female = 0 if male == 1
replace female = 1 if male == 0

label var female "Female"
label var ed4 "Education"
label var age "Age"

*label key regression variables

label var misreport "DV: `No' to birthday question"

label var disinterested "Burden-Time: Disinterested"
label var survalue_1 "Utility: Surveys are important"
label var survalue_2 "Utility: A lot can be learned"
label var truthful_4 "Truthfulness: Participants tell truth"
label var survalue_3 "Burden-Time: Waste of time"
label var mislead_4 "Intentions: Surveys manipulate/mislead"
label var ask_count "Fatigue: Times surveyed in past 12 months"

label var burden_1 "Fatigue: Too many requests to participate"
label var burden_2 "Privacy: Invasion of privacy"
label var lowerclass "Lower class"
label var noformal "No formal education"

gen region2 = 1 if region3 == 1 | region3 == 2
replace region2 = 2 if region3 == 3

label def region2 1 "Qatari/Arab" 2 "Non-Arab"
label val region2 region2

**************************************************************

*Regression tables

cd ~/Desktop/Results/

*eliminate singleton stratum in Qatar sample
*Qatari
gen strat2=strat
replace strat2=11 if strat==13 & region3==1
replace strat2=11 if strat==12 & region3==1

svyset, clear
svyset [weight=wgt], strat(strat2)


*Set macros with key variables

global IV2 = "survalue_3 disinterest survalue_1 survalue_2 mislead_4  burden_2 burden_1 ask_count truthful_4"
global dem = "noformal midupper lower"

***********************************************************************
* Summary Stats for Appendix

cd ~/Desktop/Results/

*install sutex (user-written) to produe summary stats tables
ssc install sutex

foreach var of varlist $dem {
drop if `var' == .
}

foreach var of varlist $IV2 influenced_4 {
drop  if `var' == .
}

drop if misreport == .

sutex misreport $IV2 $dem age female Ktime if region2==1, ///
	lab minmax replace file("SumArab")

sutex misreport $IV2 $dem age female Ktime if region2==2, ///
	lab minmax replace file("SumNon")

***********************************************************
*Main regression model with survey value predictors

foreach n of numlist 1/2 {

svy: logit misreport $IV2 if region2 == `n'
estimates store M`n'

}

local j = 2
*******************************************************************
*Main model with demographic controls (without age and gender)

foreach n of numlist 1/2 {
local j = `j'+1
svy: logit misreport $IV2 $dem if region2 == `n'
estimates store M`j'


}

cd ~/Desktop/Results/

esttab M1 M2 M3 M4 using Demographics+Attitudes.tex, ///
	noomit nobase notes gaps ///
	mtitles("Qatari/Arab" "Non-Arab" "Qatari/Arab" "Non-Arab") ///
	cells(b(star fmt(3)) se(par fmt(2))) style(tab) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) replace label ///
	addnotes("Standard errors in parentheses" "* p<0.05, ** p<0.01, *** p<0.001") scalars(p)

***********************************************************
***********************************************************

*Appendix Materials

*Bonferroni adjusted margins 
***********************************************
foreach n of numlist 1/2 {

svy: logit misreport $IV2 if region2 == `n'
eststo margin: margins, dydx(*) mcompare(bonferroni adjustall) post
estimates store MR`n'

}

local j = 2

*Main model with demographic controls (without age and gender)

foreach n of numlist 1/2 {
local j = `j'+1
svy: logit misreport $IV2 $dem if region2 == `n'
eststo margin: margins, dydx(*) mcompare(bonferroni adjustall) post
estimates store MR`j'


}

esttab MR1 MR2 MR3 MR4 using Bonferonni_Dem+Attitudes.tex, ///
	noomit nobase notes gaps ///
	starlevels(* 0.01 ** 0.001 *** 0.0001) replace label ///
	cells(b(star fmt(3)) se(par fmt(2))) style(tab) ///
	mtitles("Qatari/Arab" "Non-Arab" "Qatari/Arab" "Non-Arab") ///
	addnotes("Standard errors in parentheses" "* p<0.05, ** p<0.01, *** p<0.001") scalars(p)


***************************************************************

cd ~/Desktop/Results/

*Alternative models for appendix

*Nationality as predictor of misreporting

local j = 0

svy: logit misreport ib1.region3 
estimates store M1

svy: logit misreport ib3.region3 
estimates store M2

esttab M1 M2 using Regions.tex, notes nogaps nomti ///
	cells(b(star fmt(3)) se(par fmt(2))) style(tab) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) replace label ///
	addnotes("Standard errors in parentheses" "* p<0.05, ** p<0.01, *** p<0.001") scalars(p)


*Comparison of main model with an without age and gender
local j = 0

foreach n of numlist 1/2 {
	local j = `j'+1
	svy: logit misreport $IV2 $dem if region2 == `n'
	estimates store M`j'
}

local j = 2

foreach n of numlist 1/2 {
	local j = `j'+1
	svy: logit misreport $IV2 $dem age female if region2 == `n'
	estimates store M`j'
}

esttab M1 M2 M3 M4 using Robust1.tex, notes nogaps noomit ///
	mtitles("Qatari/Arab" "Non-Arab" "Qatari/Arab" "Non-Arab") ///
	cells(b(star fmt(3)) se(par fmt(2))) style(tab) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace label ///
	addnotes("Standard errors in parentheses" "* p<0.05, ** p<0.01, *** p<0.001") scalars(p)


*******************************************************************
*Main model with TIME to birthday module 

foreach n of numlist 1/2 {
svy: logit misreport $IV2 $dem if region2 == `n'
estimates store M`n'
}

local j = 2

foreach n of numlist 1/2 {
	local j = `j'+1
	svy: logit misreport $IV2 $dem Ktime if region2 == `n'
	estimates store M`j'
}

esttab M1 M2 M3 M4 using Time.tex, compress notes nogaps noomit ///
	mtitles("Qatari/Arab" "Non-Arab" "Qatari/Arab" "Non-Arab") ///
	cells(b(star fmt(3)) se(par fmt(2))) style(tab) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) replace label ///
	addnotes("Standard errors in parentheses" "* p<0.05, ** p<0.01, *** p<0.001") scalars(p)



*******************************
*	The End		
		
		
		
		
		
